﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.NodeFactory;

namespace Emic.Masterpages
{
    public partial class Contacts : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            sendButton.Click += new EventHandler(sendButton_Click);
            resetForm.Click += new EventHandler(resetForm_Click);
            FormPanel.Visible = true;
            SucessMessage.Visible = !FormPanel.Visible;

        }

        void resetForm_Click(object sender, EventArgs e)
        {
            nameTb.Text = string.Empty;
            emailTb.Text = string.Empty;
            msgTb.Text = string.Empty;
        }

        void sendButton_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
                return;

            Node currentNode = Node.GetCurrent();

            string emailFrom = currentNode.GetProperty("commonMailFrom").Value;
            string emailTo = currentNode.GetProperty("commonMailTo").Value;
            string subject = currentNode.GetProperty("commonMailSubject").Value;

            string msg = "<p><strong>Nome:</strong> " + nameTb.Text + "</p>";
            msg += "<p><strong>Email:</strong> " + emailTb.Text + "</p>";
            msg += "<p><strong>Mensagem:</strong> " + msgTb.Text + "</p>";

            ClassEmail.sendMail(emailFrom, emailTo, string.Empty, subject, msg);

            SucessMessage.Visible = true;
            successMsgLab.Text = "Thanks for your contact"; //currentNode.GetProperty("contactSuccessMessage").Value;
            FormPanel.Visible = false;
        }
    }
}